#include "SQLObjectType.h"
#include <algorithm>
#include "../../../utils/log.h"
#include "../../../utils/StringUtils.h"

SQLObjectType SQLObjectType::TABLE = SQLObjectType(make_string_ptr("TABLE"));
SQLObjectType SQLObjectType::FUNCTION = SQLObjectType(make_string_ptr("FUNCTION"));
SQLObjectType SQLObjectType::PROCEDURE = SQLObjectType(make_string_ptr("PROCEDURE"));
SQLObjectType SQLObjectType::USER = SQLObjectType(make_string_ptr("USER"));
SQLObjectType SQLObjectType::DATABASE = SQLObjectType(make_string_ptr("DATABASE"));
SQLObjectType SQLObjectType::SCHEMA = SQLObjectType(make_string_ptr("SCHEMA"));
SQLObjectType SQLObjectType::ROLE = SQLObjectType(make_string_ptr("ROLE"));
SQLObjectType SQLObjectType::PROJECT = SQLObjectType(make_string_ptr("PROJECT"));
SQLObjectType SQLObjectType::PACKAGE = SQLObjectType(make_string_ptr("PACKAGE"));
SQLObjectType SQLObjectType::RESOURCE = SQLObjectType(make_string_ptr("RESOURCE"));
SQLObjectType SQLObjectType::INSTANCE = SQLObjectType(make_string_ptr("INSTANCE"));
SQLObjectType SQLObjectType::JOB = SQLObjectType(make_string_ptr("JOB"));
SQLObjectType SQLObjectType::VOLUME = SQLObjectType(make_string_ptr("VOLUME"));
SQLObjectType SQLObjectType::OfflineModel = SQLObjectType(make_string_ptr("OFFLINEMODEL"));
SQLObjectType SQLObjectType::SYSTEM = SQLObjectType(make_string_ptr("SYSTEM"));
SQLObjectType SQLObjectType::GLOBAL = SQLObjectType(make_string_ptr("GLOBAL"));
// for odps
SQLObjectType SQLObjectType::XFLOW = SQLObjectType(make_string_ptr("XFLOW"));

SQLObjectType::SQLObjectType(string_ptr name)
{
  // LOG_INFO << "name:" << name ;
  this->name = name;
  // this->nameLCase = name.toLowerCase();
  // std::transform(name->begin(), name->end(), std::back_inserter(this->nameLCase), [](unsigned char c)
  //                { return std::tolower(c); });
  this->nameLCase = StringUtils::toLower(name);
}

SQLObjectType::SQLObjectType(SQLObjectType *sqlObjectType)
{
  this->name = sqlObjectType->name;
  this->nameLCase = sqlObjectType->nameLCase;
}

bool SQLObjectType::operator==(const SQLObjectType &rgt)
{
  LOG_INFO << "name:" << this->name << ",rgt.name:" << rgt.name;
  return this->name == rgt.name;
}
